require("./util.js");

var t = require("./myCalendar.js"), e = function(e) {
    return this.prop = {
        dateStr: void 0,
        pickDate: void 0,
        timeZone: 8,
        language: "zh-cn",
        panType: 0,
        juTypeMap: {
            0: "拆补",
            1: "置闰",
            2: "茅山",
            3: "活时"
        },
        juType: 0,
        selectJu: 1,
        ext: {
            emptyType: 0,
            attachType: 0,
            geo: void 0
        },
        attachGongMap: {
            0: "寄坤宫",
            1: "阳艮阴坤",
            2: "寄四维",
            3: "随节令"
        }
    }, this.rule = {
        gan: [ "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" ],
        zhi: [ "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" ],
        solarTerm: [ "冬至", "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪" ],
        juArr: [ "123891345456987219765654", "789567912123321543198987", "456234678789654876432321" ],
        yuanMap: {
            0: "上元",
            1: "中元",
            2: "下元"
        },
        luoshu: [ [ 4, 9, 2 ], [ 3, 5, 7 ], [ 8, 1, 6 ] ],
        turntable: [ 1, 8, 3, 4, 9, 2, 7, 6 ],
        turntable2: [ 1, 8, 3, 4, 9, 5, 2, 7, 6 ],
        doorArr: [ "休门", "生门", "伤门", "杜门", "景门", "死门", "惊门", "开门" ],
        starArr: [ "天蓬", "天任", "天冲", "天辅", "天英", "天禽", "天芮", "天柱", "天心" ],
        staticGongMap: {
            1: {
                index: 0,
                star: "天蓬",
                door: "休门"
            },
            8: {
                index: 1,
                star: "天任",
                door: "生门"
            },
            3: {
                index: 2,
                star: "天冲",
                door: "伤门"
            },
            4: {
                index: 3,
                star: "天辅",
                door: "杜门"
            },
            9: {
                index: 4,
                star: "天英",
                door: "景门"
            },
            5: {
                index: -1,
                star: "天禽",
                door: null
            },
            2: {
                index: 5,
                star: "天芮",
                door: "死门"
            },
            7: {
                index: 6,
                star: "天柱",
                door: "惊门"
            },
            6: {
                index: 7,
                star: "天心",
                door: "开门"
            }
        },
        attachFourGongMap: {
            "1,2,3,4,5,6": 8,
            "7,8,9,10,11,12": 4,
            "13,14,15,16,17,18": 2,
            "19,20,21,22,23,0": 6
        },
        attachJieQiMap: {
            "0,1,2": 1,
            "3,4,5": 8,
            "6,7,8": 3,
            "9,10,11": 4,
            "12,13,14": 9,
            "15,16,17": 2,
            "18,19,20": 7,
            "21,22,23": 6
        },
        gongStyleMap: {
            1: 1,
            8: 1,
            3: 1,
            4: 1,
            9: -1,
            2: -1,
            7: -1,
            6: -1
        },
        troops: [ "戊", "己", "庚", "辛", "壬", "癸", "丁", "丙", "乙" ],
        sixJia: [ "子", "戌", "申", "午", "辰", "寅" ]
    }, this.calendar = {}, this.panHead = {}, this.panBody = {}, this.run = function() {
        this.selectLang();
        var e = this.prop.dateStr.toDate(), r = this.calendar.glDate, a = null;
        if (this.prop.ext.geo) {
            var i = (a = t.getRealDate(e, this.prop.ext.geo.longitude)).getTime() - e.getTime();
            r = a.format("MM月dd日hh:mm"), console.log(JSON.stringify(this.prop.ext.geo) + "diffTime：" + i + "真太阳时：" + r);
        }
        this.calendar = t.solar2lunar(a || e), this.calendar.glDate = this.prop.dateStr.toDate().format("yyyy年MM月dd日hh:mm"), 
        this.calendar.realGlDate = r, this.calendar.pickDate = e, this.calendar.prevTermTimeStr = this.calendar.prevTermTime.format("yyyy-MM-dd hh:mm:ss"), 
        this.calendar.afterTermTimeStr = this.calendar.afterTermTime.format("yyyy-MM-dd hh:mm:ss"), 
        this.panHead = this.getPanHead(), this.panBody = this.getPanBody();
    }, this.getCaiBuJu = function() {
        var t = this.calendar.gzDay, e = this.getYuan(t), r = this.calendar.prevTerm, a = this.rule.solarTerm.indexOf(r), i = parseInt(this.rule.juArr[e.yuan].charAt(a));
        return a >= 12 && (i *= -1), {
            juNum: i,
            termIndex: a,
            yuan: e.yuan,
            yuanDay: e.yuanDay
        };
    }, this.getZhiRunJu = function() {
        var t = this.calendar.pickDate, e = this.calendar.gzDay, r = this.calendar.prevTerm, a = this.calendar.afterTerm, i = this.rule.solarTerm.indexOf(r), h = this.rule.solarTerm.indexOf(a), n = this.calendar.cYear, s = i < 12 ? 0 : 12;
        12 != this.calendar.cMonth && 0 == s && (n -= 1);
        var o = this.getTermDateAndHeadDay(n, s), u = i < 12 ? 12 : 0, d = this.getTermDateAndHeadDay(n, u), l = 0, y = !1, g = i;
        l = o.diffDay > 9 ? 15 - o.diffDay : 0 - o.diffDay;
        var c = o.termDate.dateAdd("d", l + i % 12 * 15);
        c = new Date(c.getFullYear(), c.getMonth(), c.getDate(), 23);
        var p = o.termDate.dateAdd("d", l + 15 * (i % 12 + 1));
        if (p = new Date(p.getFullYear(), p.getMonth(), p.getDate(), 23), console.log(i + "--" + h + "==pHeadDate:" + c.format("yyyy-MM-dd hh:mm") + "-aHeadDate:" + p.format("yyyy-MM-dd hh:mm") + "-pickDate:" + t.format("yyyy-MM-dd hh:mm")), 
        c > t ? (g = (0 == g ? 24 : g) - 1, console.log("符头大于当前时间" + g)) : c < t && p > t ? (g = i, 
        console.log("符头在中间" + g)) : p < t ? (g = h, console.log("符头小于当前时间" + g)) : console.log("error..."), 
        console.log("termIndex..." + g), h % 12 == 0) {
            var m = this.getTermDateAndHeadDay(n, h);
            console.log("当前时间大于下一个节气符头" + o.diffDay + "==" + m.diffDay + "==pickDate" + t.format("yyyy-MM-dd hh:mm") + "aHeadDate" + p.format("yyyy-MM-dd hh:mm")), 
            t > p && m.diffDay >= 9 && o.diffDay < 9 && (y = !0, g = 0 == g ? 23 : g - 1);
        }
        i % 12 == 0 && (console.log("当前时间在冬至夏至后" + o.diffDay + "==" + d.diffDay + "==" + d.termDate.format("yyyy-MM-dd hh:mm") + "==" + u), 
        t < c && o.diffDay >= 9 && d.diffDay < 9 && (y = !0));
        var f = this.getYuan(e), x = this.rule.solarTerm[g] + (y ? "（润）" : "") + this.rule.yuanMap[f.yuan] + "，第" + f.yuanDay + "天,节,isLeepTerm:" + y, H = parseInt(this.rule.juArr[f.yuan].charAt(g));
        return g >= 12 && (H *= -1), console.log("局数：" + H + "," + x), {
            juNum: H,
            termIndex: g,
            yuan: f.yuan,
            yuanDay: f.yuanDay,
            desc: x
        };
    }, this.getMaoShanJu = function() {
        var t = this.calendar.pickDate, e = (this.calendar.gzDay, this.calendar.prevTerm), r = this.rule.solarTerm.indexOf(e), a = this.calendar.prevTermTime.dateAdd("h", 120), i = this.calendar.prevTermTime.dateAdd("h", 240), h = this.calendar.prevTermTime.dateAdd("h", 360), n = 0;
        t < a ? (n = 0, console.log("上元")) : t < i ? (n = 1, console.log("中元")) : t < h ? (n = 2, 
        console.log("下元")) : (n = 2, console.log("大于下元，继续用下元"));
        var s = parseInt(this.rule.juArr[n].charAt(r));
        return r >= 12 && (s *= -1), {
            juNum: s,
            termIndex: r,
            yuan: n,
            yuanDay: 0
        };
    }, this.selectJu = function() {
        var t = this.calendar.prevTerm, e = this.rule.solarTerm.indexOf(t), r = Number(this.prop.selectJu), a = this.calendar.gzDay, i = this.getYuan(a);
        return {
            juNum: r,
            termIndex: e,
            yuan: i.yuan,
            yuanDay: i.yuanDay
        };
    }, this.getTermDateAndHeadDay = function(e, r) {
        var a = r - 1;
        0 == r && (a = 23);
        var i = t.getTermDate(e, a), h = t.solar2lunar(i).gzDay, n = this.getYuan(h);
        return {
            termDate: i,
            diffDay: 5 * n.yuan + n.yuanDay
        };
    }, this.getYuan = function(t) {
        var e = t.charAt(0), r = t.charAt(1), a = this.rule.gan.indexOf(e), i = this.rule.zhi.indexOf(r), h = (12 + i - a % 5) % 12;
        return {
            yuan: h % 3 == 0 ? 0 : h % 3 == 1 ? 2 : 1,
            yuanDay: (12 + i - h) % 12 + 1
        };
    }, this.getEarthGan = function(t) {
        var e = this.panHead.juNum;
        return e > 0 ? this.rule.troops[(9 - e + t) % 9] : this.rule.troops[Math.abs((-9 + e + t) % 9)];
    }, this.getHeadIndex = function(t) {
        var e = t.charAt(0), r = t.charAt(1), a = this.rule.gan.indexOf(e), i = this.rule.zhi.indexOf(r), h = this.rule.zhi[(12 + i - a) % 12];
        return this.rule.sixJia.indexOf(h);
    }, this.getHorse = function() {
        var t = this.calendar.gzHours.charAt(1), e = (this.rule.zhi.indexOf(t) % 4 * -3 + 12 + 2) % 12;
        return this.rule.zhi[e];
    }, this.getEmptyGongIndex = function(t) {
        var e = "";
        e = 3 == t ? this.calendar.gzYear : 2 == t ? this.calendar.gzMonth : 1 == t ? this.calendar.gzDay : this.calendar.gzHours;
        var r = this.getEmptyZhiIndexs(e), a = this.getGongIndex(r[0]), i = this.getGongIndex(r[1]);
        return new Array(a, i);
    }, this.getAllEmpty = function() {
        var t = this.calendar.gzYear, e = this.calendar.gzMonth, r = this.calendar.gzDay, a = this.calendar.gzHours, i = this.getEmptyZhiIndexs(t), h = this.getEmptyZhiIndexs(e), n = this.getEmptyZhiIndexs(r), s = this.getEmptyZhiIndexs(a);
        return {
            yEmpty: this.rule.zhi[i[0]] + this.rule.zhi[i[1]],
            mEmpty: this.rule.zhi[h[0]] + this.rule.zhi[h[1]],
            dEmpty: this.rule.zhi[n[0]] + this.rule.zhi[n[1]],
            hEmpty: this.rule.zhi[s[0]] + this.rule.zhi[s[1]]
        };
    }, this.getHideGan = function(t) {
        var e = this.getHeadIndex(t);
        return this.rule.troops[e];
    }, this.getEmptyZhiIndexs = function(t) {
        var e = this.getHeadIndex(t), r = this.rule.zhi.indexOf(this.rule.sixJia[e]);
        return [ (r - 2 + 12) % 12, (r - 1 + 12) % 12 ];
    }, this.getGongIndex = function(t) {
        return 2 * Math.floor(t / 3) + (t % 3 == 0 ? 0 : 1);
    }, this.setStyle = function(t) {
        for (var e = 0; e < t.length; e++) {
            var r = t[e], a = r.luoshu;
            r.gongStyle = this.rule.gongStyleMap[a + ""] * this.panHead.juNum > 0 ? "lightGrey" : "";
        }
    }, this.extend = function(t, e, r) {
        if (e instanceof Array) for (var a = 0, i = e.length; a < i; a++) extend(t, e[a], r);
        for (var a in e) !r && a in t || (t[a] = e[a]);
        return t;
    }, this.extend(this.prop, e, !0), this;
};

module.exports = {
    FeiPan: function(t) {
        return e.call(this, t), this.selectLang = function() {
            "zh-cn" != this.prop.language.toLowerCase() ? (this.rule.doorArr = [ "休門", "死門", "傷門", "杜門", "中五", "開門", "驚門", "生門", "景門" ], 
            this.rule.starArr = [ "天蓬", "天芮", "天沖", "天輔", "天禽", "天心", "天柱", "天任", "天英" ], this.rule.deityArr1 = [ "值符", "騰蛇", "太陰", "六合", "勾陳", "太常", "朱雀", "九地", "九天" ], 
            this.rule.deityArr2 = [ "值符", "騰蛇", "太陰", "六合", "白虎", "太常", "玄武", "九地", "九天" ]) : (this.rule.doorArr = [ "休门", "死门", "伤门", "杜门", "中五", "开门", "惊门", "生门", "景门" ], 
            this.rule.starArr = [ "天蓬", "天芮", "天冲", "天辅", "天禽", "天心", "天柱", "天任", "天英" ], this.rule.deityArr1 = [ "值符", "螣蛇", "太阴", "六合", "勾陈", "太常", "朱雀", "九地", "九天" ], 
            this.rule.deityArr2 = [ "值符", "螣蛇", "太阴", "六合", "白虎", "太常", "玄武", "九地", "九天" ]);
        }, this.getPanBody = function() {
            for (var t = this.panHead.juNum, e = new Array(), r = (new Array(), this.rule.sixJia[this.panHead.hHeadIndex]), a = this.rule.zhi.indexOf(r), i = this.panHead.hHeadNum, h = this.zhiShiIndex(), n = this.zhiFuIndex(), s = (this.calendar.gzDay.charAt(0), 
            this.calendar.gzHours.charAt(0), 0); s < 9; s++) {
                var o, u = s + 1, d = "", l = "", y = "", g = "", c = "";
                t > 0 ? (d = this.rule.gan[(9 - i + s) % 9 + 1] + this.rule.zhi[(a + (9 - i + s) % 9 + 1) % 12], 
                l = this.rule.deityArr1[(18 - i + s + 1) % 9], c = this.rule.deityArr1[(9 - n + s) % 9]) : (d = this.rule.gan[(18 + i - s - 2) % 9 + 1] + this.rule.zhi[(a + (18 + i - s - 2) % 9 + 1) % 12], 
                l = this.rule.deityArr2[(9 + i - s - 1) % 9], c = this.rule.deityArr2[(9 + n - s) % 9]), 
                o = this.getEarthGan((9 - n + s + i - 1) % 9 + 1), 2 == this.prop.panType || t > 0 ? (y = this.rule.doorArr[(9 - h + s + i - 1) % 9], 
                g = this.rule.starArr[(9 - n + s + i - 1) % 9]) : (y = this.rule.doorArr[(9 + h - s + i - 1) % 9], 
                g = this.rule.starArr[(9 + n - s + i - 1) % 9]), e[s] = {
                    luoshu: u,
                    earthGan: this.getEarthGan(u),
                    darkGz: d,
                    earthDeity: l,
                    roofDoor: y,
                    roofStar: g,
                    roofGan: o,
                    roofDeity: c
                };
            }
            this.setStyle(e);
            var p = this.rule.zhi.indexOf(this.panHead.horse), m = this.getGongIndex(p);
            e[this.rule.turntable[m] - 1].isHorse = !0;
            var f = this.getEmptyGongIndex(this.panHead.emptyType), x = this.rule.turntable[f[0]] - 1, H = this.rule.turntable[f[1]] - 1;
            e[x].isEmpty = !0, e[H].isEmpty = !0;
            var v = new Array();
            return v[0] = [ e[3], e[8], e[1] ], v[1] = [ e[2], e[4], e[6] ], v[2] = [ e[7], e[0], e[5] ], 
            v;
        }, this.getPanHead = function() {
            var t = null;
            t = 1 == this.prop.juType ? this.getZhiRunJu() : 2 == this.prop.juType ? this.getMaoShanJu() : 3 == this.prop.juType ? this.selectJu() : this.getCaiBuJu(), 
            console.log(JSON.stringify(t) + "<<<<<<<<<");
            var e = t.juNum, r = this.calendar.gzHours, a = this.getHeadIndex(r), i = "甲" + this.rule.sixJia[a] + this.rule.troops[a], h = 0;
            0 == (h = e > 0 ? (a + e) % 9 : (9 + Math.abs(e) - a) % 9) && (h = 9);
            var n = this.rule.starArr[h - 1], s = this.rule.doorArr[h - 1], o = this.getHorse(r), u = this.calendar.gzDay.charAt(0);
            "甲" == u && (u = this.getHideGan(this.calendar.gzDay));
            var d = this.calendar.gzHours.charAt(0);
            return "甲" == d && (d = this.getHideGan(this.calendar.gzHours)), {
                dayGan: u,
                hourGan: d,
                juNum: e,
                hHeadIndex: a,
                hHeadName: i,
                hHeadNum: h,
                zhiFu: n,
                zhiShi: s,
                horse: o,
                emptyType: this.prop.ext.emptyType,
                allEmpty: this.getAllEmpty()
            };
        }, this.zhiShiIndex = function() {
            var t = this.calendar.gzHours, e = this.rule.zhi.indexOf(t.charAt(1)), r = this.getHeadIndex(t), a = (e - this.rule.zhi.indexOf(this.rule.sixJia[r]) + 12) % 12;
            return this.panHead.juNum < 0 ? (this.panHead.hHeadNum - 1 - a + 9) % 9 : (this.panHead.hHeadNum - 1 + a) % 9;
        }, this.zhiFuIndex = function() {
            var t = this.calendar.gzHours, e = this.panHead.juNum, r = this.panHead.hHeadNum, a = this.rule.troops.indexOf(t.charAt(0));
            -1 == a && (a = this.panHead.hHeadIndex);
            var i = (9 + a - this.panHead.hHeadIndex) % 9;
            return e > 0 ? (r - 1 + i) % 9 : (9 + r - 1 - i) % 9;
        }, this.run(), this;
    },
    ZhuanPan: function(t) {
        return e.call(this, t), this.selectLang = function() {
            "zh-cn" != this.prop.language.toLowerCase() ? (this.rule.doorArr = [ "休門", "生門", "傷門", "杜門", "景門", "死門", "死門", "驚門", "開門" ], 
            this.rule.starArr = [ "天蓬", "天任", "天沖", "天輔", "天英", "天禽", "天芮", "天柱", "天心" ], this.rule.deityArr = [ "值符", "騰蛇", "太陰", "六合", "白虎", "玄武", "九地", "九天" ]) : (this.rule.doorArr = [ "休门", "生门", "伤门", "杜门", "景门", "死门", "惊门", "开门" ], 
            this.rule.starArr = [ "天蓬", "天任", "天冲", "天辅", "天英", "天芮", "天柱", "天心" ], this.rule.deityArr = [ "值符", "螣蛇", "太阴", "六合", "白虎", "玄武", "九地", "九天" ]);
        }, this.getPanBody = function() {
            for (var t = new Array(), e = this.rule.turntable, r = this.panHead.attachGong, a = 0; a < e.length; a++) {
                var i = this.getEarthGan(e[a]), h = this.rule.starArr[a], n = "", s = "";
                e[a] == r && (s = "天禽", n = this.getEarthGan(5)), t[a] = {
                    luoshu: e[a],
                    earthGan: i,
                    attachEarthGan: n,
                    earthStar: h,
                    attachEarthStar: s,
                    earthDoor: this.rule.doorArr[a]
                };
            }
            var o = [ {
                luoshu: 5,
                earthGan: this.getEarthGan(5),
                earthStar: "天禽",
                earthDoor: ""
            } ], u = this.panHead.earthZfIndex, d = this.zhifuIndex(t, r), l = this.zhiShiIndex(r);
            console.log("roofZsIndex:" + l + "==roofZfIndex:" + d + "===attachGong:" + r + "=========midd===>");
            var y = this.panHead.juNum, g = new Array();
            for (a = 0; a < t.length; a++) {
                var c = (8 + a + u - d) % 8;
                t[a].roofStar = t[c].earthStar, t[a].roofGan = t[c].earthGan, t[a].attachRoofStar = t[c].attachEarthStar, 
                t[a].attachRoofGan = t[c].attachEarthGan;
                var p = (8 + a - d) % 8;
                y < 0 && (p = (8 - a + d) % 8), t[a].deity = this.rule.deityArr[p];
                var m = (8 + a + u - l) % 8;
                t[a].roofDoor = t[m].earthDoor, g[a] = t[a];
            }
            this.setStyle(g);
            var f = this.rule.zhi.indexOf(this.getHorse());
            g[this.getGongIndex(f)].isHorse = !0;
            var x = this.getEmptyGongIndex(this.panHead.emptyType);
            g[x[0]].isEmpty = !0, g[x[1]].isEmpty = !0, g.splice(5, 0, o[0]);
            var H = new Array();
            return H[0] = [ g[3], g[4], g[6] ], H[1] = [ g[2], g[5], g[7] ], H[2] = [ g[1], g[0], g[8] ], 
            H;
        }, this.getPanHead = function() {
            var t = null, e = (t = 1 == this.prop.juType ? this.getZhiRunJu() : 2 == this.prop.juType ? this.getMaoShanJu() : 3 == this.prop.juType ? this.selectJu() : this.getCaiBuJu()).juNum, r = this.calendar.gzHours, a = this.getHeadIndex(r), i = "甲" + this.rule.sixJia[a] + this.rule.troops[a], h = 0;
            0 == (h = e > 0 ? (a + e) % 9 : (9 + Math.abs(e) - a) % 9) && (h = 9);
            var n = this.getAttachGong(this.prop.ext.attachType, t.termIndex), s = this.rule.staticGongMap[h + ""], o = s.star, u = s.door, d = s.index;
            if (-1 == d) {
                var l = this.rule.staticGongMap[n + ""];
                u = l.door, d = l.index, console.log("值符落中宫-寄宫attachGong:" + n + ",earthZfIndex:" + d);
            }
            var y = this.getHorse(r), g = this.calendar.gzDay.charAt(0);
            "甲" == g && (g = this.getHideGan(this.calendar.gzDay));
            var c = this.calendar.gzHours.charAt(0);
            return "甲" == c && (c = this.getHideGan(r)), {
                dayGan: g,
                hourGan: c,
                juNum: e,
                hHeadIndex: a,
                hHeadName: i,
                hHeadNum: h,
                earthZfIndex: d,
                zhiFu: o,
                zhiShi: u,
                horse: y,
                emptyType: this.prop.ext.emptyType,
                allEmpty: this.getAllEmpty(),
                attachGong: n,
                juObj: t
            };
        }, this.getAttachGong = function(t, e) {
            var r = 0;
            return r = 0 == t ? 2 : 1 == t ? e >= 12 ? 2 : 8 : 2 == t ? this.getAttachGongByTerm(this.rule.attachFourGongMap, e) : this.getAttachGongByTerm(this.rule.attachJieQiMap, e), 
            console.log("termIndex:" + e + "======>attachType" + t + ",attachGong:" + r), r;
        }, this.getAttachGongByTerm = function(t, e) {
            for (var r in t) if (r.split(",").indexOf(e + "") > -1) return t[r];
            return 2;
        }, this.zhiShiIndex = function(t) {
            var e = this.calendar.gzHours, r = this.rule.zhi.indexOf(e.charAt(1)), a = this.getHeadIndex(e), i = (r - this.rule.zhi.indexOf(this.rule.sixJia[a]) + 12) % 12, h = 0;
            0 == (h = this.panHead.juNum < 0 ? (this.panHead.hHeadNum - i + 9) % 9 : (this.panHead.hHeadNum + i) % 9) && (h = 9);
            var n = this.rule.turntable.indexOf(h);
            -1 == n && (n = this.rule.staticGongMap[t + ""].index);
            return n;
        }, this.zhifuIndex = function(t, e) {
            var r = this.calendar.gzHours, a = r.charAt(0), i = -1;
            for (var h in t) {
                var n = t[h].earthGan, s = t[h].attachEarthGan;
                n != a && s != a || (i = h);
            }
            if (-1 == i) {
                var o = this.getHeadIndex(r), u = this.rule.troops[o];
                for (var h in console.log("时柱为-六甲===>" + u + "====" + o), t) {
                    n = t[h].earthGan, s = t[h].attachEarthGan;
                    n != u && s != u || (i = h);
                }
            }
            return Number(i);
        }, this.run(), this;
    }
};